package com.shujia.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object DEmo5Filter {
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf()
      .setMaster("local")
      .setAppName("map")


    val sc = new SparkContext(conf)


    //基于集合构建RDD
    val rdd1: RDD[Int] = sc.parallelize(List(1, 2, 3, 4, 5, 6, 7, 8, 9, 0))

    /**
      *
      * filter: 过滤数据，函数返回true保留数据，函数返回false 过滤数据
      *
      */
    val rdd2: RDD[Int] = rdd1.filter((i: Int) => i % 2 == 1)

    rdd2.foreach(println)

  }

}
